package com.ruoyi.common.core.domain;

import com.ruoyi.common.constant.HttpStatus;
import lombok.Data;

/**
 * @author zhangsan
 */
@Data
public class JsonResponse<T> {
    public static final Integer CODE_SUCCESS = HttpStatus.SUCCESS;
    public static final Integer CODE_FAIL = HttpStatus.ERROR;
    public static final String MSG_SUCCESS = "操作成功";
    public static final String MSG_FAIL = "操作失败";
    private Integer code;
    private T data;
    private String msg;

    public static <T> JsonResponse<Integer> ok() {
        JsonResponse<Integer> jsonResponse = new JsonResponse<>();
        jsonResponse.code = CODE_SUCCESS;
        jsonResponse.msg = MSG_SUCCESS;
        jsonResponse.data = null;
        return jsonResponse;
    }

    public static <T> JsonResponse<T> ok(T data) {
        JsonResponse<T> jsonResponse = new JsonResponse<>();
        jsonResponse.code = CODE_SUCCESS;
        jsonResponse.msg = MSG_SUCCESS;
        jsonResponse.data = data;
        return jsonResponse;
    }

    public <T> JsonResponse<Integer> fail() {
        JsonResponse<Integer> jsonResponse = new JsonResponse<>();
        jsonResponse.code = CODE_FAIL;
        jsonResponse.msg = MSG_FAIL;
        jsonResponse.data = null;
        return jsonResponse;
    }

    public <T> JsonResponse<Integer> fail(String msg) {
        JsonResponse<Integer> jsonResponse = new JsonResponse<>();
        jsonResponse.code = CODE_FAIL;
        jsonResponse.msg = msg;
        jsonResponse.data = null;
        return jsonResponse;
    }

    /*
        public <T> JsonResponse<Integer> fail(int code, String msg) {
            JsonResponse<Integer> jsonResponse = new JsonResponse<>();
            jsonResponse.code = code;
            jsonResponse.msg = msg;
            jsonResponse.data = null;
            return jsonResponse;
        }*/
    public <T> JsonResponse<T> fail(int code, String msg) {
        JsonResponse<T> jsonResponse = new JsonResponse<>();
        jsonResponse.code = code;
        jsonResponse.msg = msg;
        jsonResponse.data = null;
        return jsonResponse;
    }
}
